import 'package:flutter/material.dart';
import 'package:flutter_app/generated/l10n.dart';
import 'package:flutter_app/components/layout.dart';
import 'language_setting.dart';

class SetPage extends StatefulWidget {
  @override
  _SetPageState createState() => _SetPageState();
}

class ListItem {
  String text;
  String rightText;
  Widget url;

  ListItem({this.text, this.url, this.rightText});
}

class _SetPageState extends State<SetPage> {
  String Language = '简体中文';
  String Version = '1.0.0';

  @override
  Widget build(BuildContext context) {
    List<ListItem> SET_ITEMS = [
      ListItem(
        text: S.of(context).language_setting,
        url: new LanguageSetting(),
        rightText: Language,
      ),
      //网络检测
      ListItem(
        text: S.of(context).net_check,
        url: null,
      ),
      //清除缓存
      ListItem(text: S.of(context).clear_cache, url: null),
      //意见反馈
      ListItem(text: S.of(context).feedback, url: null),
      //版本
      ListItem(
        text: S.of(context).version,
        url: null,
        rightText: Version,
      ),
    ];
    List<Widget> getItems() {
      return SET_ITEMS.map((item) {
        return InkWell(
          child: RowBetween(
            children: [
              Text(item.text, style: TextStyle(fontSize: 16)),
              Row(children: [
                (item.rightText != null && item.rightText.isNotEmpty)
                    ? Text(item.rightText,
                        style: TextStyle(fontSize: 16, color: Colors.grey))
                    : SizedBox.shrink(),
                Icon(Icons.arrow_forward_ios,color: Colors.grey,size: 16,)
              ])
            ],
          ),
          onTap: () {
            Navigator.push(context, MaterialPageRoute(builder: (context) {
              return item.url;
            }));
          },
        );
      }).toList();
    }

    return Scaffold(
      appBar: DarkHeadBar(S.of(context).setting),
      body: SafeArea(
          child: Padding(
        padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 18.0),
        child: Wrap(
            runSpacing: 30,
            children: getItems()
        ),
      )),
    );
  }
}
